from abc import ABC, abstractmethod

# 抽象产品：手机
class Phone(ABC):
    @abstractmethod
    def launch(self):
        pass

# 抽象产品：电脑
class Computer(ABC):
    @abstractmethod
    def launch(self):
        pass

# 抽象工厂
class AbstractFactory(ABC):
    @abstractmethod
    def create_phone(self) -> Phone:
        pass

    @abstractmethod
    def create_computer(self) -> Computer:
        pass

# 具体产品：苹果手机
class iPhone(Phone):
    def launch(self):
        return "iPhone is launched!"

# 具体产品：苹果电脑
class MacBook(Computer):
    def launch(self):
        return "MacBook is launched!"

# 假设的具体产品：另一品牌的手机
class MIPhone(Phone):
    def launch(self):
        return "MIPhone is launched!"

# 假设的具体产品：另一品牌的电脑
class MIBook(Computer):
    def launch(self):
        return "MIBook is launched!"

# 具体工厂：苹果工厂
class AppleFactory(AbstractFactory):
    def create_phone(self) -> Phone:
        return iPhone()

    def create_computer(self) -> Computer:
        return MacBook()

# 假设的具体工厂：另一品牌工厂
class MIFactory(AbstractFactory):
    def create_phone(self) -> Phone:
        return MIPhone()

    def create_computer(self) -> Computer:
        return MIBook()

# 客户端代码
class Client:
    def __init__(self, factory: AbstractFactory):
        self.factory = factory

    def run(self):
        phone = self.factory.create_phone()
        computer = self.factory.create_computer()
        print(phone.launch())
        print(computer.launch())

# 测试代码
if __name__ == "__main__":
    apple_factory = AppleFactory()
    client_apple = Client(apple_factory)
    client_apple.run()  # 输出: iPhone is launched! MacBook is launched!

    mi_factory = MIFactory()
    client_mi = Client(mi_factory)
    client_mi.run()  # 输出: MIPhone is launched! MIBook is launched!